package com.example.demo.entryWarehouse.controller;


import com.alibaba.excel.EasyExcel;
import com.example.demo.common.ResponseData;
import com.example.demo.entryWarehouse.dto.Acceptance;
import com.example.demo.entryWarehouse.entity.AcceptInform;
import com.example.demo.entryWarehouse.service.AcceptInformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangxuan
 * @since 2021-05-03
 */
@RestController
@RequestMapping("/entryWarehouse/accept-inform")
@PreAuthorize("hasAnyAuthority('4','5')")
@CrossOrigin(origins = {"*"})
public class AcceptInformController {

    @Autowired
    private AcceptInformService acceptInformService;

    //所有的验收记录
    @GetMapping("/selectAll")
    public ResponseData selectAll(){
        return acceptInformService.selectAll();
    }

    //所有未完成的验收记录
    @GetMapping("/selectByNot")
    public ResponseData selectByNot(){
        return acceptInformService.selectByNot();
    }

    //按编号查的验收记录
    @GetMapping("/selectById")
    public ResponseData selectById(@RequestParam("acceptId") String acceptId){
        return acceptInformService.selectById(acceptId);
    }

    //所有完成的验收记录
    @GetMapping("/selectByOk")
    public ResponseData selectByOk(){
        return acceptInformService.selectByOk();
    }

    //按验收状态查询
    @GetMapping("/selectByStatus")
    public ResponseData selectByStatus(@RequestParam("status") String status){
        return acceptInformService.selectByStatus(status);
    }

    //新建验收
    @PostMapping("/addAccept")
    public ResponseData addAccept(@RequestBody Acceptance acceptance){
        return acceptInformService.addAccept(acceptance);
    }

    //更改验收
    @PostMapping("/editAccept")
    public ResponseData editAccept(@RequestBody AcceptInform acceptInform){
        return acceptInformService.editAccept(acceptInform);
    }

    //更改验收状态，并入库和更新数量等操作
    @PostMapping("/editStatus")
    public ResponseData editStatus(@RequestBody AcceptInform acceptInform){
        return acceptInformService.editStatus(acceptInform);
    }

    //导出验收单
    @PostMapping("/exportAccept")
    public ResponseData exportAccept(@RequestParam("acceptId") String acceptId){
        return acceptInformService.exportAccept(acceptId);
    }

    @PostMapping("/exportAccept1")
    public void exportAccept1(HttpServletResponse response, @RequestParam("acceptId") String acceptId)throws IOException {
        acceptInformService.exportAccept1(response,acceptId);
    }

    //导出验收单
    @PostMapping("/exportReceive")
    public ResponseData exportReceive(@RequestParam("acceptId") String acceptId){
        return acceptInformService.exportReceive(acceptId);
    }

    //导出验收单
    @PostMapping("/exportReturn")
    public ResponseData exportReturn(@RequestParam("acceptId") String acceptId){
        return acceptInformService.exportReturn(acceptId);
    }



}

